﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace AdvancedGod.People.Couples
{
  /// <summary>
  /// Contains util methods for coupling
  /// </summary>
  internal class CouplingUtils
  {
    #region internal static methods
    /// <summary>
    /// Gets pertient couple attribute for first human with pair with same type
    /// as second human 
    /// </summary>
    /// <param name="firstHuman">first human</param>
    /// <param name="secondHuman">second human</param>
    /// <returns></returns>
    internal static CoupleAttribute FindPertientCoupleAttribute(Human firstHuman,
      Human secondHuman)
    {
      IList<CoupleAttribute> attributes = firstHuman.GetAttributeEnumeration();
      Func<CoupleAttribute, bool> predicate = attr => attr.Pair.Equals(secondHuman.GetType().Name);
      CoupleAttribute pertientAttribute = attributes.FirstOrDefault(predicate);
      if (pertientAttribute == null)
      {
        throw new NoAttributeException(firstHuman.GetType(), secondHuman.GetType());
      }
      return pertientAttribute;
    }
    #endregion
  }
}
